@section('title', '文章编辑')
@section('content')
   
    <div class="layui-form-item">
        <label class="layui-form-label">名称：</label>
        <div class="layui-input-block">
            <input type="text" value="{{$article_data['title'] or ''}}" name="title"  required lay-verify="title" placeholder="请输入名称" autocomplete="off" class="layui-input">
        </div>

    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">热搜：</label>
        <div class="layui-input-block">
            <input type="radio" name="hot_bot" value="1" title="是">
            <input type="radio" name="hot_bot" value="0" title="否" checked>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">阅读量：</label>
        <div class="layui-input-block">
            <input type="text" value="{{$article_data['read_num'] or ''}}" name="read_num" required lay-verify="required|number"  autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">文章内容：</label>
        <div class="layui-input-block">
            <textarea id="content" name="content" style="display: none;" placeholder="请输入内容">{{$article_data['content'] or ''}}</textarea>
        </div>
    </div>

@endsection
@section('id',$id)
@section('js')
    <script>
        
        layui.use(['form','layedit', 'layer','upload'], function() {
            var form = layui.form;
            form.render();
            var $=layui.jquery
                    ,layedit=layui.layedit
                    ,layer = layui.layer;
            form.verify({
                title: [/^.{2,12}$/, '文章名长度2到12位之间'],
            });
            var layedit_index=layedit.build('content'); //建立编辑器
            form.on('submit(formDemo)', function(data) {
                  layedit.sync(layedit_index);
//                var layedit_content=layedit.getContent(layedit_index)
//                var lar_data=data.field;
//                lar_data['content']=layedit_content;
                $.ajax({
                    url:"{{url('/article')}}",
                    data:$('form').serialize(),
//                    data:lar_data,
                    type:'post',
                    dataType:'json',
                    success:function(res){
                        if(res.status == 1){
                            layer.msg(res.msg,{icon:6});
                            var index = parent.layer.getFrameIndex(window.name);
                            setTimeout('parent.layer.close('+index+')',2000);
                            //parent.layer.close(index);
                        }else{
                            layer.msg(res.msg,{shift: 6,icon:5});
                        }
                    },
                    error : function(XMLHttpRequest, textStatus, errorThrown) {
                        console.log(XMLHttpRequest.status);
                        console.log(XMLHttpRequest.msg);
//                        layer.msg('网络失败', {time: 1000});
                    }
                });
                return false;
            });
        });
    </script>
@endsection
@extends('common.edit')
